﻿<KCtl:BaseUserControl xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"  x:Class="Kiva7.Pages.SearchLoansControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:KCtl="clr-namespace:Kiva7.Controls"
    mc:Ignorable="d"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    d:DesignHeight="480" d:DesignWidth="480"
    KCtl:TiltEffect.IsTiltEnabled="True">
    <Grid>

        <ProgressBar Visibility="{Binding IsLoaded, Converter={StaticResource booleanToNotVisibility}}" 
                     IsIndeterminate="{Binding IsLoaded, Converter={StaticResource notBooleanConverter}}" 
                     Style="{StaticResource CustomIndeterminateProgressBar}"
                     VerticalAlignment="Center" />

        <ListBox x:Name="lbxLoans" Margin="0,0,-12,0" ItemsSource="{Binding Data}" 
              Background="{StaticResource KivaBackgroundBrush}"
             HorizontalContentAlignment="Stretch" SelectionChanged="lbxLoans_SelectionChanged"
                 Visibility="{Binding IsLoaded, Converter={StaticResource booleanToVisibility}}">

            <ListBox.ItemTemplate>

                <DataTemplate>

                    <StackPanel Margin="0,0,0,17" >

                        <Grid>

                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="80" ></ColumnDefinition>
                                <ColumnDefinition ></ColumnDefinition>
                            </Grid.ColumnDefinitions>

                            <Grid.RowDefinitions>
                                <RowDefinition></RowDefinition>
                                <RowDefinition></RowDefinition>
                            </Grid.RowDefinitions>

                            <StackPanel Grid.Column="0" Grid.Row="0"  Style="{StaticResource KivaListItemImageStyle}">
                            <Button Width="78" Click="Button_Click" BorderThickness="0">
                                <Grid HorizontalAlignment="Right" VerticalAlignment="Top">
                                    <Image Source="\Images\basket_icon.png" 
                                           Visibility="{Binding IsSelected, Converter={StaticResource booleanToNotVisibility}}"/>
                                    <Image Source="\Images\appbar.check.rest.png" 
                                           Visibility="{Binding IsSelected, Converter={StaticResource booleanToVisibility}}"/>
                                </Grid>
                            </Button>
                            <Image x:Name="imgLender" Source="{Binding Image.SmallImageUrl}" Width="78"
                            VerticalAlignment="Top" HorizontalAlignment="Center"
                                Visibility="{Binding Image, Converter={StaticResource objectVisibility}}" Margin="0,12,0,0" />
                            </StackPanel>

                            <StackPanel Grid.Column="1" Grid.Row="0" Grid.RowSpan="2" Style="{StaticResource KivaListItemStyle}"
                                        Width="378">

                                <TextBlock Text="{Binding Name}" TextWrapping="Wrap" 
                               Style="{StaticResource KivaTextGroupHeaderStyle}"/>

                                <toolkit:WrapPanel Orientation="Horizontal">
                                    <TextBlock Text="{Binding Location.Country}"
                                   Style="{StaticResource KivaTextSmallStyle}"/>

                                    <TextBlock Text="{Binding Location.Town}"
                                   Style="{StaticResource KivaTextSmallStyle}"/>

                                    <TextBlock Text="{Binding PostedDate, Converter={StaticResource toShortDate}}" 
                                   Style="{StaticResource KivaTextSmallStyle}"/>
                                </toolkit:WrapPanel>

                                <toolkit:WrapPanel Orientation="Horizontal">
                                    <TextBlock Text="{Binding Path=L.Amount, Source={StaticResource L}}" Margin="12,0,0,0" 
                                    Style="{StaticResource KivaTextAccentStyle}"/>
                                    <TextBlock Text="{Binding LoanAmount, Converter={StaticResource toAmount}}" Margin="12,0,0,0" 
                                    Style="{StaticResource KivaTextAccentStyle}"/>

                                    <TextBlock Text="{Binding Path=L.Needed, Source={StaticResource L}}" Margin="18,0,0,0" 
                                    Style="{StaticResource KivaTextAccentStyle}"/>

                                    <TextBlock Text="{Binding FundsNeeded, Converter={StaticResource toAmount}}" Margin="12,0,0,0"  
                                    Style="{StaticResource KivaTextAccentStyle}"/>
                                </toolkit:WrapPanel>

                                <TextBlock Text="{Binding Use}" TextWrapping="Wrap" 
                               Style="{StaticResource KivaTextNormalStyle}"/>

                            </StackPanel>
                        </Grid>
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </Grid>
</KCtl:BaseUserControl>
